
$(function () {
  // 交换名片
  $('#showExchangeCard').click(function () {
    $('#exchangeCard').show();
  })
  // 名片列表
  $('#businessCard table td input[type=button]').click(function () {
    $('#businessCard ul li').removeClass('active').show().eq(1).addClass('active');
    $('#businessCard .dialog_content').hide().eq(1).show();
  })
  // 名片列表&名片详情：切换
  $('#businessCard ul li').click(function () {
    var index = $('#businessCard ul li').index($(this));
    if (index == 0) {
      $('#businessCard ul li').removeClass('active').show().eq(0).addClass('active');
      $('#businessCard ul li').eq(1).hide();
      $('#businessCard .dialog_content').hide().eq(0).show();
    }
  })
  // 当面交流
  $('#showFaceToFace').click(function () {
    $('#faceToFace .dialog_content').hide().eq(0).show();
    $('#faceToFace').show();
  })
  // 视频接通
  $('#videoCall').click(function () {
    $('#faceToFace .dialog_content').hide().eq(1).show();
  })

  // close or cancel
  $('.icon_close, .input_cancel').click(function () {
    var modalDialog = $(this).parents('.modalDialog');
    modalDialog.eq(0).hide()
  })

  // swiper-slider

  var viewSwiper = new Swiper('.view .swiper-container', {
    onSlideChangeStart: function () {
      updateNavPosition()
    }
  })

  $('.view .arrow-left,.preview .arrow-left').on('click', function (e) {
    e.preventDefault()
    if (viewSwiper.activeIndex == 0) {
      viewSwiper.slideTo(viewSwiper.slides.length - 1, 1000);
      return
    }
    viewSwiper.slidePrev()
  })
  $('.view .arrow-right,.preview .arrow-right').on('click', function (e) {
    e.preventDefault()
    if (viewSwiper.activeIndex == viewSwiper.slides.length - 1) {
      viewSwiper.slideTo(0, 1000);
      return
    }
    viewSwiper.slideNext()
  })

  var previewSwiper = new Swiper('.preview .swiper-container', {
    //visibilityFullFit: true,
    slidesPerView: 'auto',
    allowTouchMove: false,
    slidesPerView: 5,
    onTap: function () {
      viewSwiper.slideTo(previewSwiper.clickedIndex)
    }
  })

  function updateNavPosition() {
    $('.preview .active-nav').removeClass('active-nav')
    var activeNav = $('.preview .swiper-slide').eq(viewSwiper.activeIndex).addClass('active-nav')
    if (!activeNav.hasClass('swiper-slide-visible')) {
      if (activeNav.index() > previewSwiper.activeIndex) {
        var thumbsPerNav = Math.floor(previewSwiper.width / activeNav.width()) - 1
        previewSwiper.slideTo(activeNav.index() - thumbsPerNav)
      } else {
        previewSwiper.slideTo(activeNav.index())
      }
    }
  }
})